package com.credit.jumu.playcard.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.credit.jumu.playcard.R;

/**
 * Created by Administrator on 2017/10/25/025.
 */

public class ChooseImageDialog {
	public Dialog mDialog;
	private TextView camera;
	private TextView image;
	private TextView close;
	private OnClickCallBack mOnClickCallBack;

	public interface OnClickCallBack {
		public void onChooseCamera();

		public void onChoosePhoto();
	}

	public ChooseImageDialog(Context context, final OnClickCallBack mOnClickCallBack) {
		mDialog = new Dialog(context, R.style.chooseimagedialog);
		this.mOnClickCallBack = mOnClickCallBack;
		initView();
	}


	class ChooseCameraClick implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			if (mOnClickCallBack != null) {
				mOnClickCallBack.onChooseCamera();
			}
		}
	}

	class ChoosePhotoClick implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			if (mOnClickCallBack != null) {
				mOnClickCallBack.onChoosePhoto();
			}
		}
	}


	private void initView() {
		mDialog.setContentView(R.layout.dialog_headimage);
		mDialog.setCanceledOnTouchOutside(false);
		mDialog.getWindow().setGravity(Gravity.BOTTOM);
		camera = mDialog.findViewById(R.id.camera);
		image = mDialog.findViewById(R.id.image);
		close = mDialog.findViewById(R.id.close);
		camera.setOnClickListener(new ChooseCameraClick());
		image.setOnClickListener(new ChoosePhotoClick());
		close.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cancelDialog();
			}
		});
	}

	public void showDialog() {
		if (null != mDialog) {
			mDialog.show();
		}
	}


	public void cancelDialog() {
		if (null != mDialog || mDialog.isShowing()) {
			mDialog.cancel();
		}
	}

}
